package com.framework.core.exception;

import android.text.TextUtils;

/**
 * @author shenmengchao
 * @version 1.0.0
 * @date 2017/7/23
 * @description
 */

public class SystemException extends BaseException {

    public final static String RESPONSE_CODE_SYSTEM_ERROR = "999";      //系统异常
    public final static String RESPONSE_CODE_OPERATE_FAILED = "1000";     //操作失败
    public final static String RESPONSE_CODE_POST_NOT_EXIST = "1009";     //Post不存在

    public SystemException(String errCode, String errMsg) {
        super(errCode, errMsg);
    }

    public SystemException(String errCode) {
        super(errCode, "");
    }

    public static boolean isSystemException(String errMsg) {
        if (RESPONSE_CODE_SYSTEM_ERROR.equals(errMsg)
                || RESPONSE_CODE_OPERATE_FAILED.equals(errMsg)
                || RESPONSE_CODE_POST_NOT_EXIST.equals(errMsg)) {
            return true;
        }
        return false;
    }

    @Override
    public String getMessage() {
        if (!TextUtils.isEmpty(getErrMsg())) {
            return getErrMsg();
        }
        String errMsg = "";
        switch (getErrCode()) {
            case RESPONSE_CODE_SYSTEM_ERROR:
                errMsg = "系统异常";
                break;
            case RESPONSE_CODE_OPERATE_FAILED:
                errMsg = "操作失败";
                break;
            case RESPONSE_CODE_POST_NOT_EXIST:
                errMsg = "Post不存在";
                break;
            default:
                break;
        }
        return errMsg;
    }
}
